package com.jcy.jcyrxjava;

import android.app.Activity;
import android.content.Context;

import com.jcy.jcyrxjava.module.request.ArticleWrapper;
import com.jcy.jcyrxjava.net.RetrofitHelper;
import com.trello.rxlifecycle2.components.support.RxAppCompatActivity;
import com.zhpan.idea.net.common.ResponseObserver;
import com.zhpan.idea.utils.RxUtil;
import com.zhpan.idea.utils.ToastUtils;

public class Controller {
    //获取数据
   public setDataCallBack mCallBack;

    public Controller(setDataCallBack mCallBack) {
        this.mCallBack = mCallBack;
    }
    //调接口
    public void getData(RxAppCompatActivity mActivity){
        RetrofitHelper.getApiService()
                .getArticle()
                .compose(RxUtil.rxSchedulerHelper(mActivity, true))
                .subscribe(new ResponseObserver<ArticleWrapper>() {
                    @Override
                    public void onSuccess(ArticleWrapper response) {
                        if (mCallBack != null){
                            mCallBack.resultData(response);
                        }else {
                            ToastUtils.show("11111111111111");
                        }
                    }
                    @Override
                    public void onFail(String message) {
                        super.onFail(message);
                    }
                });
    }
}
